package com.example.superoa.controller;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.example.superoa.model.pojos.BecomeWorker;
import com.example.superoa.model.pojos.Contract;
import com.example.superoa.model.pojos.Department;
import com.example.superoa.model.pojos.Entry;
import com.example.superoa.model.pojos.Jobchage;
import com.example.superoa.model.pojos.Position;
import com.example.superoa.model.pojos.Staff;
import com.example.superoa.model.service.EntryService;
import com.example.superoa.model.service.StaffService;
import com.example.superoa.model.vo.EntryVo;
import com.example.superoa.model.vo.StaffVo;

@Controller
public class StaffController {
	@Autowired
	private StaffService staffservice;
	
	@Autowired
	private EntryService entryservice;
	//员工花名册
	@RequestMapping("ljj-staff")
	public void staff() {
	}
	//员工入职管理新增页面
	@RequestMapping("ljj-entry-add")
	public void entryadd() {
		
	}
	//查询员工表数据
	@RequestMapping("staffbg-list")
	@ResponseBody
	public List<StaffVo> StaffList(){
		return staffservice.staffAll();
		
	}
	//获取员工数据
	@RequestMapping("staff-update")
	@ResponseBody
	public Staff staffById(int staff_id,Model model) {
		//System.err.println(staffservice.staffById(staff_id).getStaff_name());
		//System.err.println(staffservice.staffById(staff_id).getStaffYears());
		return staffservice.staffById(staff_id);
	}
	//修改员工信息
	@PostMapping("xiugai-staff")
	@ResponseBody
	public void XiugaiContract(Staff staff_id) {
		System.err.println(staff_id);
		staffservice.staffedit(staff_id);
	}
	
	//条件查询
	@RequestMapping("select-mhcx")
	@ResponseBody
	public JSONArray SelectMhcx(@Param("staff_name")String staff_name) {
		return staffservice.staffselect(staff_name);
	}
	
	//员工入职多表添加
	@PostMapping("insert-duobiao")
	public String adddbtj(Staff e,Contract cnm,Entry en,BecomeWorker be,
			Department d,String entystate,String staff_sfzz,String bwr_state,Integer position_id,Position p,Jobchage j) {
		System.out.println(e);
		System.err.println("职位ID"+position_id);
		System.out.println(cnm);
		e.setDepartment(d);
		e.setContract(cnm);
		en.setStaff(e);
		be.setStaff(e);
		e.setStaff_sfzz("未在职"); 
		cnm.setContreact_qdstate("未签订");
		en.setEntystate("待入职");
		be.setBwr_state(0);
 		staffservice.adddbtj(e, cnm,en,be,d,position_id,p,j);
		return "redirect:main-administrator:ljj-staff";
	}
	
	//查询入职信息
	@RequestMapping("entry-list")
	@ResponseBody
	public List<EntryVo> entryAll(){
		return entryservice.entryAll();
		
	}
	//审核入职
	@PostMapping("ruzhi-shenhe")
	@ResponseBody
	public void ruzhiState(String Entystate,int Entryid,String Staff_sfzz,int staffId) {
		staffservice.ruzhiState("已入职", Entryid);
		staffservice.xiugaizt("已在职", staffId);
	}
	//查询入职
	@RequestMapping("chaxun-shenhe")
	@ResponseBody
	public EntryVo entryAll(int entryid,Model model) {
		System.err.println(staffservice.entryAll(entryid));
		return staffservice.entryAll(entryid);
	}
	@RequestMapping("staff-xx")
	@ResponseBody
	public void select(Staff staffId) {
		//return staffservice.selectaaa(staffId);
	}
}
